#ifndef __BSP_MC_PID_REGULATORS__H
#define __BSP_MC_PID_REGULATORS__H

#ifdef __cplusplus
extern "C" {
#endif
	
#include "bsp_mc_type.h"



/* default values for Torque control loop */
#define PID_TORQUE_REFERENCE   (s16)0 //(N.b: that's the reference init  //value in both torque and speed control)
#define PID_TORQUE_KP_DEFAULT  (s16)1000//500//1500//1500     
#define PID_TORQUE_KI_DEFAULT  (s16)1000//2000//800//800
#define PID_TORQUE_KD_DEFAULT  (s16)0

/* default values for Flux control loop */
#define PID_FLUX_REFERENCE   (s16)0
#define PID_FLUX_KP_DEFAULT  (s16)1000//500//1500//1500
#define PID_FLUX_KI_DEFAULT  (s16)1000//2000//800//1000
#define PID_FLUX_KD_DEFAULT  (s16)0

// Toruqe/Flux PID  parameter dividers
#define TF_KPDIV ((u16)(2048))
#define TF_KIDIV ((u16)(16384))
#define TF_KDDIV ((u16)(0))

/* default values for Speed control loop */
#define PID_SPEED_REFERENCE_RPM   0
#define PID_SPEED_KP_DEFAULT      (s16)2000//4000//1200//2500
#define PID_SPEED_KI_DEFAULT      (s16)50//100//50//200
#define PID_SPEED_KD_DEFAULT      0

#define PID_LOWSPEED_KP_DEFAULT   500

/* Speed PID parameter dividers          */
#define SP_KPDIV ((u16)(256))
#define SP_KIDIV ((u16)(16384))
#define SP_KDDIV ((u16)(0))

#define IQMAX  7500//dec xianfiu
#define IQMIN  10000//inc xianfu



void PID_Init (PID_Struct_t *PID_Torque, PID_Struct_t *PID_Flux, PID_Struct_t *PID_Speed);
s16 PI_Regulator(s16 hReference, s16 hPresentFeedback, PID_Struct_t *PID_Struct);
s16 Speed_PI_Regulator(s16 hReference, s16 hPresentFeedback, PID_Struct_t *PID_Struct);
void FOC_CalcFluxTorqueRef(float rpmset,float rpmfb);




#ifdef __cplusplus
}
#endif

#endif 













